<template>
  <CompOperate
      :field="field"
      :designer="designer"
      :design-state="designState"
      :parent-list="parentList"
      :parent-widget="parentWidget"
      :sub-form-row-id="subFormRowId"
      :sub-form-row-index="subFormRowIndex"
      :sub-form-col-index="subFormColIndex"
      :index-of-parent-list="indexOfParentList"
      :display-style="field.options.displayStyle"
  >
    <div class="scene-waiting-current-waiting-art" :style="getStyle('area')">
      <template v-if="true">
        <div class="room-area queue-item">
          <div class="item-info" v-for="(item,index) in doctorPatientList"
               :key="`${item.workerId}-${index}`">
            <ScrollX>
              <template v-if="optionsInfo['titleType']==='treatmentRoomName-registerObjNames'">
                {{item['treatmentRoomName']}} {{item['registerObjNames']}}
              </template>
              <template v-else>
                {{item[optionsInfo['titleType']] || item['deptName'] ||  '\u00a0'}}
              </template>
            </ScrollX>
          </div>
        </div>
        <div class="current-header-area queue-item">
          <div class="item-info"
               v-for="(item,index) in doctorPatientList"
               :style="getStyle('currentTitle')"
               :key="`${item.workerId}-${index}`">
            <span>{{ optionsInfo['currentPaperwork'] }}</span>
          </div>
        </div>
        <div class="current-area queue-item">
          <div class="item-info" v-for="(item,index) in doctorPatientList"
               :style="getStyle('currentTitle')"
               :key="`${item.workerId}-${index}`">
            <ScrollX>{{ getCurrentPatient(item) }}</ScrollX>
          </div>
        </div>

        <div class="waiting-area">
          <div class="title" :style="getStyle('waitingTitle')">
            <ScrollX>
              {{ optionsInfo['waitingPaperwork'] }}
            </ScrollX>
          </div>
          <div class="content" v-if="true">
            <div class="content-inside"
                 v-for="(itemInfo, index) in waitingChunkInfos"
                 :key="index"
                 :data-key="index"
                 :class="{'even':((index+1)%2)===0}"
            >
              <div class="content-inside-child" v-for="(itemInfo2, itemInfoKey2) in itemInfo"
                 :key="`${itemInfo2.queuingId}-${itemInfoKey2}`" :style="getStyle('waitingTitle')">
                <div class="child-inside" v-if="true">
                  {{ itemInfo2.orderNo || '\u00a0' }}{{ itemInfo2.patientName || '\u00a0' }}
                </div>
              </div>
            </div>
          </div>
        </div>
      </template>
    </div>
  </CompOperate>
</template>

<script>
import {pxToVw} from '@/utils/common';
import emitter from "@/utils/designer/emitter";
import ScrollX from '@c/public/seamlessScroll/ScrollX.vue'
import CompOperate from "@c/public/form-designer/devType/modules/compOperate.vue";
import mixin from "@sc/templateDetails/modules/homeMiddle/fieldMixin";
import {buildParentApi} from "@/utils/designer/util";
let buildParent = buildParentApi();
export default {
  name: "scene-waiting-current-waiting-art-widget",

  componentName: "FieldWidget", //必须固定为FieldWidget，用于接收父级组件的broadcast事件

  mixins: [emitter, mixin],

  components: {
    CompOperate,
    ScrollX
  },

  props: {
    widget: Object,
    field: Object,
    parentWidget: Object,
    parentList: Array,
    indexOfParentList: Number,
    designer: Object,
    designState: {
      type: Boolean,
      default: false,
    },
    devType: {
      type: Boolean,
      default: false,
    },
    subFormRowIndex: {
      /* 子表单组件行索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormColIndex: {
      /* 子表单组件列索引，从0开始计数 */ type: Number,
      default: -1,
    },
    subFormRowId: {
      /* 子表单组件行Id，唯一id且不可变 */ type: String,
      default: "",
    },

    headTitle: {
      type: String,
      default: "",
    },
    visibleTitle: {
      type: Boolean,
    },
  },

  data() {
    return {
      waitingPatientNumber:0
    }
  },

  computed: {
    // 设置的行内样式
    getStyle() {
      return function (val) {
        const self = this;
        let info = (self.optionsInfo) || Array();
        let Obj = Object();
        switch (val) {
          case 'area':
            Reflect.set(Obj, 'height', pxToVw(info.areaHeight));
            return Obj;
          case "currentTitle":
            Reflect.set(Obj, 'fontSize', pxToVw((info.currentFontSize) || 50));
            return Obj;
          case "waitingTitle":
            Reflect.set(Obj, 'fontSize', pxToVw((info.waitingFontSize) || 50));
            return Obj;
        }
      }
    },

    //  队列-患者-数据
    doctorPatientList() {
      let data;
      let devType = (this.devType);
      let WaitingPatientList = this.$store.getters['getWaitingPatientInfo'];
      if (devType) {
        data = (WaitingPatientList.apiData)
      } else {
        data = (WaitingPatientList.mockData)
      }
      if (data && !!(data.length)) {
        return data.slice(0, 3);
      } else {
        return [{waitPatientList: []},{waitPatientList: []},{waitPatientList: []}]
      }
    },

    // 当前就诊的患者|| 医生暂停接诊
    getCurrentPatient() {
      return function (val) {
        /**
         * 在线状态 0在线 1暂停 2退出
         */
        let type = parseInt(val.onlineStatus);
        switch (type) {
          case 0:
          case 2:
            if (!!(val.treatingPatient) && !!(val.treatingPatient.length)) {
              let currentPatient = Array();
              (val.treatingPatient).forEach((item) => {
                let temp = `${(item.orderNo) || '\u00a0'} ${(item.patientName) || '\u00a0'}`
                currentPatient.push(temp)
              })
              let info = this.$lodash.join(currentPatient, ' ')
              return (this.$lodash.trim(info));
            } else {
              return '\u00a0'
            }
          case 1:
            return '暂停接诊';
        }
      }
    },

    // 切割候诊患者
    waitingChunkInfos() {
      let data = (this.doctorPatientList);
      let summary = this.$lodash.map(data, "waitPatientList");
      if(!!summary&&!!(summary.length)){
        let flattenArr = this.$lodash.flattenDeep(summary)
        this.waitingPatientNumber = (flattenArr.length) || 0
        if (flattenArr.length > 12) {
          let flattenArr2 = flattenArr.slice(0, 12);
          return this.$lodash.chunk(flattenArr2, 4)
        } else {
          let arr = (new Array(12 - flattenArr.length).fill({}));
          let flattenArr2 = [...flattenArr, ...arr];
          return this.$lodash.chunk(flattenArr2, 4)
        }
      }else {
        let arrInfo = (new Array(12).fill({}));
        return this.$lodash.chunk(arrInfo, 4)
      }

    },
  },

  created() {
    this.registerToRefList();
    this.initEventHandler();
    this.handleOnCreated();
  },

  mounted() {
    this.handleOnMounted();
  },

  methods: {
    // 接收父组件传递过来的数据
    executeMethod(key, data) {
      switch (key) {
        case "patientListInfo":
          let patientList = this.$lodash.cloneDeep(data);
          buildParent.executeParentMethod('writeLog', JSON.stringify({sign:'模板-患者信息',key:key,data:data}));
          this.$store.dispatch('setWaitingPatientInfo', patientList);
          break
      }
    }
  },

  watch: {
    field: {
      handler: function (val) {
        let key = (val.options.config);
        this.optionsInfo = (val.options[key]);
      },
      deep: true,
      immediate: true
    }
  },

  destroyed() {
    this.unregisterFromRefList();
  },
};
</script>

<style lang="scss" scoped>
.scene-waiting-current-waiting-art {
  padding: 28px 155px 10px 155px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  color: #333;
  height: auto;
  font-size: 50px;
  background: transparent;
  font-family: 'sharkFitHealth', serif !important;


  .queue-item {
    display: flex;
    flex-direction: row;
    background: white;
    border-radius: 30px;
    overflow: hidden;
    margin-bottom: 6px;
    height: 99px;
    line-height: 99px;

    .item-info {
      min-width: calc(100% / 3);
      display: flex;
      align-self: center;
      align-items: center;
      text-align: center;
      width: 100%;
      justify-content: center;
    }
  }

  //诊室
  .room-area {
    border-radius: 30px;
    overflow: hidden;
    color: white;
    font-size: 50px;
    height: 110px;
    line-height: 110px;
    background: rgba(14, 182, 201, 1);
    .item-info {
      @include singleEllipsis(100%);
      padding: 0 20px;
    }
  }

  //正在就诊
  .current-header-area {
    .item-info {
      box-sizing: border-box;
      padding: 0 14px;
      span {
        flex: 1;
        border-radius: 20px;
        overflow: hidden;
        height: 80px;
        line-height: 80px;
        background: rgba(204, 222, 240, 1);
      }
    }
  }

  //就诊患者
  .current-area{
    .item-info {
      padding: 0 40px;
      @include singleEllipsis(100%)
    }
  }

  //等待就诊
  .waiting-area {
    display: flex;
    margin-top: 14px;
    flex-direction: column;


    .title {
      background: rgba(14, 182, 201, 1);
      text-align: center;
      font-size: 50px;
      height: 108px;
      width: 100%;
      color:white;
      border-bottom: 2px solid #DDDDDD;
      display: flex;
      align-self: center;
      align-items: center;
      border-radius: 24px 24px;
      overflow: hidden;
      justify-content: center;
      .scrollText{
        display: flex;
        align-items: center;
        align-self: center;
        justify-content: center;
        text-align: center;
        width: 100%;
        height: 100%;
      }
      .st-scrolling{
        overflow: hidden;
        display: flex;
        align-items: center;
      }
    }

    .content {
      display: flex;
      flex-wrap: wrap;

      .content-inside {
        width: 100%;
        display: flex;
        margin-bottom: 8px;
        flex-wrap: wrap;
        height: 106px;
        border-radius: 24px 24px;
        overflow: hidden;
        .content-inside-child {
          flex-basis: calc(100% / 4);
          font-weight: 400;
          text-align: center;
          display: flex;
          justify-content: center;
          align-self: center;
          align-items: center;
          font-family: 'sharkFitHealth', serif !important;
          font-size: 48px;
          color: #333333;
          overflow: hidden;
          .child-inside{
            padding: 0 24px;
            @include singleEllipsis(100%)
          }
        }
      }
    }

    .content-inside{
      background: white;
    }
    .even {
      background: rgba(244, 244, 244, 1);
    }
  }

}
</style>
